<template>
    <div>
        <el-row>
        <b>当前进度：</b>
        <el-radio-group v-model="radio1" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">待分配工单</el-radio-button>
        <el-radio-button label="2">待工程确认</el-radio-button>
        <el-radio-button label="3">待维修</el-radio-button>
        <el-radio-button label="4">已完成</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>维修类型：</b>
        <el-radio-group v-model="radio2" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">水路</el-radio-button>
        <el-radio-button label="2">电路</el-radio-button>
        <el-radio-button label="3">门窗</el-radio-button>
        <el-radio-button label="4">公共设施</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>工单来源：</b>
        <el-radio-group v-model="radio3" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">业主上报</el-radio-button>
        <el-radio-button label="2">公司推送</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="repairLocation"
        label="维修地点">
      </el-table-column>
      <el-table-column
        prop="type"
        label="维修类型">
        <template slot-scope="scope">
            <el-tag :type="scope.row.tagColor">{{ scope.row.type }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="progress"
        label="当前进度">
        <template slot-scope="scope">
            <el-tag :type="scope.row.tagColor">{{ scope.row.progress }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="申请时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-search" @click="ToRepairInfo(scope.row.id)" >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
    </div>
</template>

<script>
export default {
    name:'repair',
    data(){
        return{
            radio1: "0",
            radio2: "0",
            radio3: "0",
            tableData: [],
            currentPage:1,
            pageSize:10,
            total:0,
        }
    },
    created(){
        this.initAuthority()
    },
    methods:{
        initAuthority(){
        this.$request.get("/role/authority",{
          params:{
            id: JSON.parse(localStorage.getItem("admin")).id,
            index: 13
          }
        })
        .then(res =>{
          this.Authority = res.data
          if(res.data == '1'){
            this.initTable()
          }else{
            this.$message.error("你没有权限访问此功能")
            // this.$router.push("/")
          }
        })
        .catch(err =>{
          console.log(err)
        })

      },
        ToRepairInfo(id){
            this.$router.push({
            path: 'repairInfo',
            query:{
                ID:id
            }
           })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.initTable()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.initTable()
        },
        initTable(){
            this.$request.get("/repair/page",{
                params:{
                    page: this.currentPage,
                    size: this.pageSize,
                    repairType:this.radio2,
                    repairProgress:this.radio1,
                    source:this.radio3,
                }
            }).then(res => {
                this.tableData = res.data.records
                this.total = res.data.total
            }).catch(err =>{
                console.log(err)
            })
        },
    }
}
</script>

<style>
    .el-row{
        margin-bottom: 20px;
    }
</style>